package com.yuanlrc.hotel.home;

import com.yuanlrc.hotel.restaurant.domain.Restaurant;
import com.yuanlrc.hotel.restaurant.service.IRestaurantService;
import com.yuanlrc.hotel.restaurantPicture.domain.RestaurantPicture;
import com.yuanlrc.hotel.restaurantPicture.service.IRestaurantPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/home/index")
public class HomeRestaurantController {
    @Autowired
    private IRestaurantService restaurantService;
    @Autowired
    private IRestaurantPictureService restaurantPictureService;
    /*
     * 餐厅展示，及餐厅菜品图片展示
     * 只展示餐厅图库中最新的四条纪录
     */
    @RequestMapping("/restaurant")
    public String restaurant(Model model){
        List<Restaurant> restaurants = restaurantService.selectRestaurantList(new Restaurant());
        RestaurantPicture restaurantPicture = null;
        for (Restaurant restaurant : restaurants) {
            restaurantPicture = new RestaurantPicture();
            restaurantPicture.setFid(restaurant.getId());
            restaurant.setList(restaurantPictureService.selectFourRestaurantPicture(restaurantPicture));
        }
        model.addAttribute("restaurants",restaurants);
        return "home/index/food";
    }
}
